export default {
	namespaced:true,
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address') || '{}'),
		token:uni.getStorageSync('token') || '',
		userinfo:JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		redirectInfo:null
	}),
	mutations:{
		// 更新收获地址
		updateAddress(state,address){
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		// 更新用户信息
		updateUserInfo(state,userinfo){
			state.userinfo = userinfo
			this.commit('m_user/saveUserInfo')
		},
		saveUserInfo(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		// 更新用户头像
		updateUserAvatarUrl(state,avatarUrl){
			state.userinfo.avatarUrl = avatarUrl
			this.commit('m_user/saveUserInfo')
		},
		// 更新用户名称
		updateUserName(state,name){
			state.userinfo.nickName = name
			this.commit('m_user/saveUserInfo')
		},
		// 更新用户Token
		updateToken(state,token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		saveTokenToStorage(state){
			uni.setStorageSync('token',state.token)
		},
		// 更新页面定向跳转之前的url信息
		updateRedirectInfo(state,info){
			state.redirectInfo = info
		}
	},
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}